package com.hualan.sfzy.service.impl.permission;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.permission.PointsMapper;
import com.hualan.sfzy.model.entity.Permission;
import com.hualan.sfzy.model.entity.Points;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PointsServiceImpl implements BaseService<Points> {
    @Autowired
    private PointsMapper pointsMapper;

    @Override
    public int add(Points points) {
        return pointsMapper.insert(points);
    }

    @Override
    public int edit(Points points) {
        return pointsMapper.update(points);
    }

    @Override
    public int remove(Integer id) {
        return pointsMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return pointsMapper.deleteBatch(ids);
    }

    @Override
    public List<Points> find() {
        return pointsMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Points points) {
        PageHelper.startPage(pageNum, pageSize);
        List<Points> list = pointsMapper.select(points);
        PageInfo<Points> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST,list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public Points findById(Integer id) {
        return pointsMapper.selectByUserId( id);
    }
}
